from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
	
#Applicant Data Model Classes
class ApplicantStub(db.Model):
    password = db.TextProperty() #required=True)
    first_name = db.TextProperty() #required=True)
    middle_initial = db.TextProperty()
    last_name = db.TextProperty() #required=True)
    cell_phone_number = db.PhoneNumberProperty() #required=True)
    email_address = db.EmailProperty()
    security_question_answer = db.TextProperty()
    email_or_text = db.TextProperty() #required=True)
    comments = db.TextProperty(indexed=False)

#Constructors & Posting Of Data
class PostApplicantStub(webapp.RequestHandler):
    def post(self):
    	applicant = ApplicantStub( #Constructor
        password = self.request.get("txtPassword"),
        first_name = self.request.get("txtFirstName"),
        middle_initial = self.request.get("txtMiddleInitial"),
        last_name = self.request.get("txtLastName"),
        cell_phone_number = self.request.get("inPhoneNumber"),
        email_address = self.request.get("txtEmailAdd"),
        security_question_answer = (self.request.get("txtSecQuestion")+self.request.get("txtSecQuestionAnswer")),
        email_or_text = self.request.get("selMessage"),
        comments = self.request.get("txtComments"),
        key_name = self.request.get("inPhoneNumber"))
        applicant.put()
        self.redirect('/ShowEntities')
	
#Start of HomeWebPage
class HomeWebPage(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        self.response.out.write('''
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="em">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
		<title>ResEdge - Home Page 07/07/2012</title>
		<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
	</head>
	<body id="tab1">
	<img src="/Images/RawHeader1100.gif" />
	<ul id="tabnav">
	<li class="tab1"><a href="HomeWebPage">Home</a></li>
	<li class="tab2"><a href="GetStarted1">Get Started</a></li>
	<li class="tab3"><a href="/admin/">Retrieve Results</a></li>
	<li class="tab4"><a href="/admin/">Employers Portal</a></li>
	<li class="tab5"><a href="/admin/">F.A.Q.</a></li>
	<li class="tab6"><a href="/admin/">About ResEdge</a></li>
	</ul>
<p>Click the <button type=button id="btnGetStarted" style="color:blue" onClick="location.href='/GetStarted1'"/>Get Started!</button> button.</p>
<p>
<a href="/admin/">Admin Page</a></p>
</body>
</html>
''')
#End of HomeWebPage
        
#GetStarted1 page - First Page of Info Gathering
class GetStarted1(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        self.response.out.write('''
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="em">
<html>
	<head>		
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
		<title>ResEdge - Get Started Page 1</title>
		<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
	</head>
	<body id="tab2">
	<img src="/Images/RawHeader1100.gif" />
	<ul id="tabnav">
	<li class="tab1"><a href="/HomeWebPage">Home</a></li>
	<li class="tab2"><a href="/GetStarted1">Get Started</a></li>
	<li class="tab3"><a href="/admin/">Retrieve Results</a></li>
	</ul>
<form id="frmFirstForm" action="/firstfrm" method="post" name="frmElecConsent">
First Name: <input type="text" name="txtFirstName" /> Middle Initial: <input type="text" name="txtMiddleInitial" /> Last Name: <input type="text" name="txtLastName" /><br>
What Password Would You Like To Use: <input type="password" name="txtPassword" /><br><br>
Alright, now a phone number and email address:<br>
Cell Phone #: <input type="tel" name="inPhoneNumber" /> Email Address: <input type="text" name="txtEmailAdd" /><br>
Would you rather have messages from us go to Email or Text Message to Cell Phone? <input type="radio" name="selMessage" value="Email" checked="selected" /> Email<input type="radio" name="selMessage" value="CellPhone" /> Cell Phone<br>
<hr>Please select a Security Question and provide an Answer:<br>
<select name="txtSecQuestion"><option value="1">Mothers' Maiden Name:</option><option value="2">Favorite Color:</option><option value="3">Favorite Season:</option><option value="4">Favorite Month:</option></select> Answer: <input type="text" name="txtSecQuestionAnswer" />
<input type="submit" name="btnSubmitFirstSheet" value="Next" />
</form>
<a href="/ShowEntities">Show Entities</a></p>
<a href="/admin/">Admin Page</a></p>
<hr>
<p>Click the <button type=button id="btnFinGetStarted" style="color:blue" onClick="location.href='/firstfrm'"/>Finished!</button> button to Submit Your ResEdge Information.</p>
</body>
</html>
	''')
#End of GetStarted1

#START: ShowEntitiesPage
class ShowEntities(webapp.RequestHandler):
    def get(self):
        self.response.headers["Content-Type"] = "text/html"
        self.response.out.write("""<html><head><title>ResEdge Show Entities Test Page</title></head>
           <body><p>This is the Show Entities Page!""")
        # Output a list of ApplicantStub entities
        q = db.Query(ApplicantStub)
#        messages = ApplicantStub.all()
#        messages.order("first_name")
#        messagesResults = messages.fetch(limit=40)
        for ApplicantStub in q:
        	self.response.out.write("<p>Name: %s</p><p>Email Address: %s</p>" % (ApplicantStub.first_name, ApplicantStub.email_address))
#        messages = db.GqlQuery('SELECT * From ApplicantStub')
#        for each_I in messages:
#            self.response.out.write("<p>Name: %s</p><p>Email Address: %s</p>" % (each_I.first_name, each_I.email_address))
		#	self.response.out.write("<p>Key: %s</p>" % (each_I.Key))
        # Link back to GetStarted Page
        self.response.out.write("""<p><a href="/GetStarted1">GetStarted Page</a></p></body></html>""")
#END: ShowEntitiesPage 

# Show Home Page - Start Here
'''class HomePage(webapp.RequestHandler):
    def get(self):
		self.redirect("/stylesheets/Home.html")
'''
           
def main():
    application = webapp.WSGIApplication([
        ('/', HomeWebPage),
        ('/HomeWebPage', HomeWebPage),
        ('/GetStarted1', GetStarted1),
    	('/firstfrm', PostApplicantStub),
    	('/ShowEntities', ShowEntities),
        ], debug=True)

    run_wsgi_app(application)

if __name__ == '__main__':
    main()